package cn.kgc.itrip.biz.service.impl;

import cn.kgc.itrip.beans.common.ResponseCode;
import cn.kgc.itrip.beans.common.ServerResponse;
import cn.kgc.itrip.beans.model.pojo.ItripHotel;
import cn.kgc.itrip.beans.model.vo.*;
import cn.kgc.itrip.biz.service.IHotelService;
import cn.kgc.itrip.mapper.itripAreaDic.ItripAreaDicMapper;
import cn.kgc.itrip.mapper.itripHotel.ItripHotelMapper;
import cn.kgc.itrip.mapper.itripHotelRoom.ItripHotelRoomMapper;
import cn.kgc.itrip.mapper.itripImage.ItripImageMapper;
import cn.kgc.itrip.mapper.itripLabelDic.ItripLabelDicMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 阿泽
 */
@Service("iHotelService")
@Slf4j
public class HotelServiceImpl implements IHotelService {
    @Resource
    ItripAreaDicMapper itripAreaDicMapper;
    @Resource
    ItripImageMapper itripImageMapper;
    @Resource
    ItripHotelMapper itripHotelMapper;
    @Resource
    ItripLabelDicMapper itripLabelDicMapper;
    @Resource
    ItripHotelRoomMapper itripHotelRoomMapper;

    @Override
    public ServerResponse<List<ItripAreaDicVO>> queryTradeList(Integer cityId) {
        if (cityId == null || cityId == 0) {
            log.error("在查询城市商圈时发生了参数丢失");
            return ServerResponse.createByErrorMessage(ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }
        return ServerResponse.createBySuccess(itripAreaDicMapper.queryTradeArea(cityId));
    }

    @Override
    public ServerResponse<List<ItripHotelImgVo>> queryHotelImage(long targetId, String type) {
        if (StringUtils.isBlank(type)) {
            type = "0";
        }
        return ServerResponse.createBySuccess(itripImageMapper.queryHotelImage(targetId, type));
    }

    @Override
    public ServerResponse queryHoteDesc(String hotelId) {
        if (StringUtils.isBlank(hotelId)) {
            log.error("根据酒店id查询酒店特色、商圈、酒店名称时发生了参数丢失");
            return ServerResponse.createByErrorMessage(ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }
        /**
         * 酒店名称
         */
        String HotelName = itripHotelMapper.queryHotelName(Long.parseLong(hotelId));

        /**
         * 酒店特色
         */
        List<String> HotelCharacteristic = itripAreaDicMapper.queryHotelCharacteristic(Long.parseLong(hotelId));
        /**
         * 商圈
         */
        List<String> HotelBusiness = itripAreaDicMapper.queryHotelBusiness(Long.parseLong(hotelId));

        ItripHoteldescVo itripHoteldescVo = new ItripHoteldescVo();

        itripHoteldescVo.setHotelName(HotelName);
        itripHoteldescVo.setHotelFeatureList(HotelCharacteristic);
        itripHoteldescVo.setTradingAreaNameList(HotelBusiness);
        return ServerResponse.createBySuccess(itripHoteldescVo);
    }

    /**
     * 根据酒店id查询酒店设施
     *
     * @param hotelId
     * @return
     */
    @Override
    public ServerResponse queryhotelfacilities(Integer hotelId) {
        if (hotelId == 0 || hotelId == null) {
            log.error("根据酒店id查询酒店设施时发生了参数丢失");
            return ServerResponse.createByErrorMessage(ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }
        ItripHotel ItripHotel = null;
        try {
            ItripHotel = itripHotelMapper.getItripHotelById(Long.parseLong(String.valueOf(hotelId)));

        } catch (Exception e) {
            e.printStackTrace();
        }


        return ServerResponse.createBySuccess(ItripHotel.getFacilities());
    }

    @Override
    public ServerResponse queryhotelfeature() {
        return ServerResponse.createBySuccess(itripLabelDicMapper.queryhotelfeature());
    }

    @Override
    public ServerResponse queryhotcity(Integer type) {
        if (type == 0 || type == null) {
            log.error("查询热门城市时发生了参数丢失");
            return ServerResponse.createByErrorMessage(ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }
        return ServerResponse.createBySuccess(itripAreaDicMapper.queryhotcity(type));
    }

    @Override
    public ServerResponse queryhoteldetails(Integer id) {
        if (id == 0 || id == null) {
            log.error("根据酒店id查询酒店特色和介绍成功时发生了参数丢失");
            return ServerResponse.createByErrorMessage(ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }
        ItripHotel itripHotel = itripHotelMapper.queryhoteldetails(id);
        List<ItripLabelDivdetailsVo> queryhoteldetails1 = itripLabelDicMapper.queryhoteldetails(id);

        ItripLabelDivdetailsVo itripLabelDivdetailsVo = new ItripLabelDivdetailsVo();

        itripLabelDivdetailsVo.setName("酒店介绍");
        itripLabelDivdetailsVo.setDescription(itripHotel.getDetails());
        queryhoteldetails1.add(itripLabelDivdetailsVo);
        return ServerResponse.createBySuccess(queryhoteldetails1);
    }

    /**
     * 根据酒店id查询酒店政策
     */
    @Override
    public ServerResponse queryhotelpolicy(Integer id) {
        if (id == 0 || id == null) {
            log.error("根据酒店id查询酒店政策时发生了参数丢失");
            return ServerResponse.createByErrorMessage(ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }
        return ServerResponse.createBySuccess(itripHotelMapper.queryhotelpolicy(id));
    }

    /**
     * 查询酒店房间床型列表
     *
     * @return
     */
    @Override
    public ServerResponse queryhotelroombed() {

        return ServerResponse.createBySuccess(itripLabelDicMapper.queryhotelroombed());
    }

    /**
     * 查询酒店房间列表
     *
     * @return
     */
    @Override
    public ServerResponse queryhotelroombyhotel(SearchHotelRoomVo roomVO) {

        if (roomVO.getEndDate() == null || roomVO.getStartDate() == null || roomVO.getHotelId() == null) {
            return ServerResponse.createBySuccessMessage("参数有误");
        }
        //查询出来的list
        List<itripSerchRoomListVo> list = itripHotelRoomMapper.queryhotelroombyhotel(roomVO);
        //List当中包含list
        List<List<itripSerchRoomListVo>> list1 = new ArrayList<>();
        for (itripSerchRoomListVo roomListVo : list){
            List<itripSerchRoomListVo> list2=new ArrayList<>();
            list2.add(roomListVo);
            list1.add(list2);
        }
        return ServerResponse.createBySuccess("查询成功",list1);
    }

    /**
     * 获取酒店相关信息（酒店名称、酒店星级）
     * @param hotelId
     * @return
     */
    @Override
    public ServerResponse gethoteldesc(String hotelId) {
        if (hotelId == null) {
            log.error("获取酒店相关信息时发生了参数丢失");
            return ServerResponse.createByErrorMessage(ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }
        ItripHoteldescsVo hoteldesc = itripHotelMapper.getHoteldesc(Long.parseLong(hotelId));
        if (hoteldesc == null) {
            return ServerResponse.createByErrorMessage("未查到改酒店信息");
        }
        return ServerResponse.createBySuccess(hoteldesc);
    }


}
